
//
//  UIButton+Extension.swift
//  weibo10
//
//  Created by mac on 15/10/17.
//  Copyright © 2015年 itheima. All rights reserved.
//

import UIKit

extension UIButton{
    
    convenience init(imageName:String,backImageName:String?){
        self.init()
        
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)

        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        if let backImageName = backImageName {
            setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
            setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
        }
        // 大小
        sizeToFit()
    }
    convenience init(title:String,color:UIColor, imageName:String){
        self.init()
        setTitle(title, forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setTitleColor(color, forState: UIControlState.Normal)
    }
    convenience init(title:String,fontSize:CGFloat, color:UIColor, imageName:String){
        self.init()
        setTitle(title, forState: UIControlState.Normal)
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setTitleColor(color, forState: UIControlState.Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    }
}

